local bizheng = fk.CreateSkill{
    name = "wk_heg__bizheng",
}

Fk:loadTranslationTable{
   ["wk_heg__bizheng"] = "弼政",
   [":wk_heg__bizheng"] = "每回合限一次，当前回合角色的牌于出牌阶段内因弃置而置入弃牌堆后，你可获得之并将X张牌置于牌堆顶，"..
   "然后其获得〖制衡〗直至其回合开始。（X为其已明置武将牌上技能数）",

   ["$wk_heg__bizheng1"] = "弼亮四世，正色率下。",
   ["$wk_heg__bizheng2"] = "弼佐辅君，国事正法。",
}

local function getTrueSkills(player)
  local skills = {}
  for _, s in ipairs(Fk.generals[player.general]:getSkillNameList()) do
    table.insertIfNeed(skills, s)
  end
  for _, s in ipairs(Fk.generals[player.deputyGeneral]:getSkillNameList()) do
    table.insertIfNeed(skills, s)
  end
  return skills
end

bizheng:addEffect(fk.AfterCardsMove,{
  anim_type = "special",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(bizheng.name) and player:usedSkillTimes(bizheng.name, Player.HistoryTurn) == 0 and player.room.current.phase == Player.Play then
      local room = player.room
      local current = room.current
      local cards = {}
      for _, move in ipairs(data) do
        if move.moveReason == fk.ReasonDiscard and move.toArea == Card.DiscardPile and move.from and move.from == current and not move.from.dead then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              table.insert(cards, info.cardId)
              cards = room.logic:moveCardsHoldingAreaCheck(cards)
            end
          end
        end
      end
      if #cards > 0 then
        event:setCostData(self, { cards = cards })
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:moveCards{
      ids = event:getCostData(self).cards,
      to = player,
      toArea = Card.PlayerHand,
      moveReason = fk.ReasonJustMove,
      proposer = player,
      skillName = bizheng.name,
    }
    local card = player:getCardIds("he")
    local skills = #getTrueSkills(room.current)
    if #card > skills then
      card = room:askToCards(player,{
        min_num = skills,
        max_num = skills,
        include_equip = true,
        skill_name = bizheng.name,
        cancelable = false,
      })
    end
    if #card == 0 then return end
    if #card > 1 then
      room:moveCards({
        ids = card,
        from = player,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonPut,
        skillName = bizheng.name,
        proposer = player,
      })
      --乐
      room:askToGuanxing(player,{
          cards = room:getNCards(#card, "top"),
          bottom_limit = {0, 0},
          skill_name = bizheng.name,
        })
      room:handleAddLoseSkills(room.current, "wk_heg__zhiheng", nil)
    end
  end,
})

return bizheng